import {
  getListPage
} from '@/api/proceeds'
import {
  UploaderImage,
  Kindeditor
} from '@/layout/components'
export default {
  components: {
    UploaderImage,
    Kindeditor
  },
  filters: { // 字段转换
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      empty_text: '暂无数据',
      listPages: {
        page: 1,
        size: 10,
        sizes: [1, 2, 3, 4, 5, 10, 15, 20, 30, 50, 100],
        total: 0
      },
      listParam: {
        page: 1,
        pageSize: 10
      },
      datas: [],
      listLoading: false
    }
  },
  created() {
    this._fetchData()
  },
  watch: {
    listParam: {
      handler() {
        this._fetchData()
      },
      deep: true // 深度监听，同时也可监听到param参数变化
    },
    listPages: {
      handler() {
        this._fetchData()
      },
      deep: true // 深度监听，同时也可监听到param参数变化
    }
  },
  methods: {
    _fetchData() {
      this.listLoading = true
      this.listParam.page = this.listPages.page
      this.listParam.pageSize = this.listPages.size
      getListPage(this.listParam).then(response => {
        this.datas = response.result.list
        this.listPages.total = response.result.total
        this.listLoading = false
      })
    },
    _page_size_change(val) {
      // console.log(`每页 ${val} 条`)
      this.listPages.size = val
    },
    _page_prev_click() {
      this.listPages.page--
    },
    _page_current_change(val) {
      // console.log(`当前页: ${val}`)
      this.listPages.page = val
    },
    _page_next_click() {
      this.listPages.page++
    },
    _exportData() {
      this.$router.push({
        path: 'billInfo',
        query: {}
      })
    },
    detailRow(row) {
      this.$router.push({
        path: 'transaction',
        query: {
          orderNo: row.orderNo,
          username: row.username
        }
      })
    }
  }
}
